// 封装本地存储工具类
export const useStorage = (storageType = 'localStorage') => {
  const storage = storageType === 'localStorage' ? window.localStorage : window.sessionStorage;

  // 设置存储项
  const setItem = (key, value) => {
    storage.setItem(key, JSON.stringify(value));
  };

  // 获取存储项
  const getItem = (key) => {
    const item = storage.getItem(key);
    return item ? JSON.parse(item) : null;
  };

  // 删除存储项
  const removeItem = (key) => {
    storage.removeItem(key);
  };

  // 清空所有存储项
  const clear = () => {
    storage.clear();
  };

  return {
    setItem,
    getItem,
    removeItem,
    clear,
  };
};